package com.mooc.meetingfilm.utils.common.vo;

import com.mooc.meetingfilm.utils.exception.CommonServiceException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <h1>表现层公共返回</h1>
 */
@Data
public class BaseResponseVO<T> {

    private Integer code;     // 状态码
    private String message;   // 消息
    private T data;           //业务数据

    private BaseResponseVO() {}

    // 成功但是无参数
    public static BaseResponseVO success() {
        BaseResponseVO response = new BaseResponseVO();
        response.setCode(200);
        response.setMessage("");
        return response;
    }

    // 成功有参数
    public static<T> BaseResponseVO success(T data) {
        BaseResponseVO response = new BaseResponseVO();
        response.setCode(200);
        response.setMessage("");
        response.setData(data);
        return response;
    }

    // 出现业务异常
    public static BaseResponseVO serviceException(CommonServiceException e) {
        BaseResponseVO response = new BaseResponseVO<>();
        response.setCode(e.getCode());
        response.setMessage(e.getMessage());
        return response;
    }
}
